<?php
/*
 * @Author: lokei
 * @Date: 2022-12-31 11:30:36
 * @LastEditors: lokei
 * @LastEditTime: 2022-12-31 12:16:45
 * @Description: 
 */
namespace App\Http\Controllers\Widget;

use App\Common\Tools\ResultTool;
use App\Http\Controllers\Controller;
use App\Middle\NavMiddle;
use App\Models\Widget\NavModel;
use Illuminate\Http\Request;

class NavController extends Controller {
    public function list(Request $request) {
        $items = NavModel::where('mode', '=', $request->input('mode'))->get();
        if(count($items) == 0) {
            NavMiddle::reset($request->input('mode'));
            $items = NavModel::where('mode', '=', $request->input('mode'))->get();
        }
        $res = ResultTool::success();
        $res['data']['nav_list'] = $items;
        return $res;
    }
    public function displayList(Request $request) {
        $items = NavModel::where('mode', '=', $request->input('mode'))->where('display', '=', '1')->get();
        $res = ResultTool::success();
        $res['data']['items'] = $items;
        return $res;
    }
    public function update(Request $request) {
        $nav = NavModel::where('id', '=', $request->input('id'))->first();
        $nav->name = $request->input('name');
		$nav->img = $request->input('img');
		$nav->url = $request->input('url');
		$nav->wxapp_url = $request->input('wxapp_url');
		$nav->display = $request->input('display');
        $nav->save();
        return ResultTool::success();
    }
    public function add(Request $request) {
        $nav = new NavModel();
        $nav->mode = $request->input('mode');
        $nav->save();
        return ResultTool::success();
    }
    public function delete(Request $request) {
        NavModel::where('id', '=', $request->input('id'))->delete();
        return ResultTool::success();
    }
}